<?php
/*
 * @Author: your name
 * @Date: 2020-10-13 17:25:46
 * @LastEditTime: 2020-12-28 14:08:07
 * @LastEditors: Please set LastEditors
 * @Description: 防火钱原始规则(在netfilter模块初始化后有客户端上传至服务器目前仅供展示)
 * @FilePath: /special/application/adminapiv3/controller/module_manage/netfilter/FirewallOriginRuleController.php
 */

namespace app\adminapiv3\controller\module_manage\netfilter;

use app\adminapiv3\service\module_manage\netfilter\FirewallOriginRuleService;
use think\facade\Request;

class FirewallOriginRuleController extends NetfilterBaseController
{

    /**
    * @name: 原始规则列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 15:42:02
     */
    public function originRuleList ()
    {
        $input = Request::only(['content','host_id'], 'post');
        $this->validate($input, 'FirewallOriginRule.listFilter');
        
        $FirewallOriginRuleService = new FirewallOriginRuleService();
        $data = $FirewallOriginRuleService->originRuleList($input);

        return $this->jsonOutPut($data);
    }

    /**
     * @name: 原始规则删除
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-10-31 15:42:30
     */
    public function originRuleDelete ()
    {
        $input = Request::only(['id', 'host_id'], 'post');
        $this->validate($input, 'FirewallOriginRule.delete');

        $FirewallOriginRuleService = new FirewallOriginRuleService();
        $FirewallOriginRuleService->originRuleDelete($input,$input['id']);

        //下发命令 查询规则列表
        $this->sendCommandToClient('netfilter','downloadRules');
        return $this->jsonOutPut();
    }

    /**
     * @name: 启用规则
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-11-05 13:36:57
     */
    public function on ()
    {
        $input = Request::only(['id', 'host_id'], 'post');

        $this->validate($input, 'FirewallOriginRule.onOff');

        $FirewallOriginRuleService = new FirewallOriginRuleService();
        $data = $FirewallOriginRuleService->on($input['host_id'], $input['id']);

        //下发命令 查询规则列表
        $this->sendCommandToClient('netfilter','downloadRules');
        return $this->jsonOutPut($data);
    
    }

    /**
     * @name: 禁用规则
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-11-05 13:36:40
     */
    public function off ()
    {
        $input = Request::only(['id', 'host_id'], 'post');
        $this->validate($input, 'FirewallOriginRule.onOff');

        $FirewallOriginRuleService = new FirewallOriginRuleService();
        $data = $FirewallOriginRuleService->off($input['host_id'], $input['id']);

        //下发命令 查询规则列表
        $this->sendCommandToClient('netfilter','downloadRules');
        return $this->jsonOutPut($data);
    }
}